package com.edu.service.impl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import com.edu.dao.HistoryDao;
import com.edu.dao.impl.HistoryDaoImpl;
import com.edu.entiy.Book;
import com.edu.entiy.BookType;
import com.edu.entiy.History;
import com.edu.entiy.User;
import com.edu.service.HistoryService;
import com.edu.utils.PageTool;

public class HistoryServiceImpl implements HistoryService{
	private HistoryDao historyDao = new HistoryDaoImpl();
	@Override
	public PageTool<History> selectByPage(String currentPage, String pageSize,Integer userId,Integer status) {
		// TODO Auto-generated method stub
		//查询总记录数据
		int count = historyDao.selectHistoryCount(userId,status);
		//初始化分页工具
		PageTool<History> pageTool = new PageTool<History>(count,currentPage,pageSize);
		System.out.println("看看用户id"+userId);
		List<History> historys =  historyDao.selectHistoriesByPage(pageTool.getStartIndex(),pageTool.getPageSize(),userId,status);
		pageTool.setRows(historys);
		return pageTool;
	}
	@Override
	public Boolean returnBook(Book book, User user, History history) {
		// TODO Auto-generated method stub
		history.setStatus(1);
		history.setRealTime(new Timestamp(new Date().getTime()));
		user.setLendMaxNum(user.getLendMaxNum()+1);
		book.setBookNum(book.getBookNum()+1);
		return historyDao.returnBook(history, book, user);
	}
	@Override
	public History selectHistory(int id) {
		// TODO Auto-generated method stub
		return historyDao.selectHistoryById(id);
	}
	@Override
	public void updateEndTime(Timestamp endTime, int historyId) {
		// TODO Auto-generated method stub
		historyDao.updateHistoryEndTime(endTime, historyId);
	}
	@Override
	public History selectByBookId(int bookId) {
		// TODO Auto-generated method stub
		return historyDao.selectByBookId(bookId);
	}
	@Override
	public History selectByCard(int card) {
		// TODO Auto-generated method stub
		return historyDao.selectByCard(card);
	}
	@Override
	public History selectByuserId(int userId) {
		// TODO Auto-generated method stub
		return historyDao.selectByuserId(userId);
	}




}
